package exercise;

/**
 * https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
 */
public class Test2 {
    public static int removeDuplicates(int[] nums) {
        int n = nums.length;
        int j = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i] != nums[j]) {
                nums[++j] = nums[i];
            }
        }
        return j + 1;
    }

    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 2, 3, 4, 4, 5, 6, 6, 8};
        int i = removeDuplicates(nums);
        for (int j = 0; j < i; j++) {
            System.out.print(nums[j] + ",");
        }

    }
}
